{{- if .Values.migration.enabled }}
apiVersion: batch/v1
kind: Job
metadata:
  name: {{ .Values.appName }}-migration
spec:
  ttlSecondsAfterFinished: 15
  template:
    metadata:
      name: {{ .Values.appName }}-migration
      labels:
        date: "{{ now | unixEpoch }}"
    spec:
      volumes:
        - name: {{ .Values.appName }}-sqlite
          persistentVolumeClaim:
            claimName: {{ .Values.appName }}-sqlite
      containers:
      - name: {{ .Values.appName }}-migrate
        image: {{ .Values.app.image }}
        command: {{ .Values.migration.command }}
        env:
        {{- include "app.env" . | nindent 8 }}
        volumeMounts:
          - mountPath: {{ .Values.app.sqlite.path }}
            name: {{ .Values.appName }}-sqlite
      restartPolicy: Never
{{- end }}
